package com.luych.toolbox.common.feign.intf.base.service;

import com.luych.toolbox.common.constant.PageConstant;
import com.luych.toolbox.common.feign.FeignInterface;
import com.luych.toolbox.common.feign.param.base.service.UserParam;
import com.luych.toolbox.common.feign.view.base.service.UserView;
import com.luych.toolbox.common.page.CommonPageResult;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@FeignClient(contextId = "base-service-user", name = "base-service", path = "/user", decode404 = true)
public interface UserFeign extends FeignInterface<UserView, UserParam> {

    @ApiOperation("为用户添加角色")
    @PostMapping("/{userId}/role/{roleId}")
    void addRole(
            @ApiParam(value = "用户ID") @PathVariable("userId") String userId,
            @ApiParam(value = "角色ID") @PathVariable("roleId") String roleId
    );

    @ApiOperation("为用户删除角色")
    @DeleteMapping("/{userId}/role/{roleId}")
    void removeRole(
            @ApiParam(value = "用户ID") @PathVariable("userId") String userId,
            @ApiParam(value = "角色ID") @PathVariable("roleId") String roleId
    );

    @ApiOperation("按登录名查询用户")
    @GetMapping("/search/login-name/{loginName}")
    UserView getByLoginName(
            @ApiParam(value = "登录名") @PathVariable("loginName") String loginName
    );

    @ApiOperation("按关键字查询用户信息")
    @GetMapping("/search/keyword")
    CommonPageResult<UserView> pageByKeyword(
            @ApiParam(value = "每页容量") @RequestHeader(name = "pageSize", required = false, defaultValue = PageConstant.DEFAULT_PAGE_SIZE_STR) long pageSize,
            @ApiParam(value = "查询页码") @RequestHeader(name = "pageNumber", required = false, defaultValue = PageConstant.DEFAULT_PAGE_NUMBER_STR) long pageNumber,
            @ApiParam(value = "排序字段") @RequestHeader(name = "sort", required = false, defaultValue = PageConstant.DEFAULT_PAGE_SORT) String sort,
            @ApiParam(value = "正序/倒序，取值ASC/DESC") @RequestHeader(name = "order", required = false, defaultValue = PageConstant.DEFAULT_PAGE_ORDER) String order,
            @ApiParam(value = "查询关键字，支持按登录名和用户名模糊查询") @RequestParam(name = "keyword", required = false) String keyword
    );

    @ApiOperation("查询所有在线用户")
    @GetMapping("/online")
    List<UserView> online();

}
